package com.logger.servlet;

import java.io.File;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.logger.service.HtmlCreator;

/**
 * Servlet implementation class HtmlCreatorServlet
 */
public class HtmlCreatorServlet extends HttpServlet
{

	private static final long	serialVersionUID	= 1L;

	/**
	 * Default constructor.
	 */
	public HtmlCreatorServlet()
	{
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		handlerRequest(request, response);
	}

	private void handlerRequest(HttpServletRequest request, HttpServletResponse response)
			throws IOException
	{
		String logString = request.getParameter("logname");
		// System.out.println("创建页面请求：" + logName);
		System.out.println("收到请求");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html; charset=utf-8");
		HtmlCreator.getInstance().createHtml(logString, response.getWriter());
		// response.getWriter().println(
		// "<br/><br/><a href='/output'>see all page</a>");
	}

	// private String createHtml(String logName)
	// {
	// if (logName != null && !logName.trim().equals(""))
	// {
	// File outDir = new File(realPath, LOG_HTML_DIR_NAME);
	// if (!outDir.exists())
	// outDir.mkdirs();
	// boolean success = HtmlCreator.getInstance().createHtml(
	// new File(LOG_FILE_DIR, logName + ".txt"), new File(outDir, logName +
	// ".html"));
	// if (success)
	// {
	// return "<a href='/" + LOG_HTML_DIR_NAME + "/" + logName +
	// ".html'>生成成功</a>";
	// }
	// }
	// return "生成失败！ LogName : " + logName;
	// }

	// private static final String LOG_FILE_DIR_DEFAULT = "Y:\\temp\\";
	public static final String	LOG_HTML_DIR_NAME	= "output";
	public static File			LOG_FILE_DIR;
	public static String		realPath;
}
